$(function() {
	var sn = $(".inHouse_menu .menu_left #sn");
	getFocus(sn);

	sn.bind('input propertychange', function() {
		if(sn.val().length == 4) {
			var data = {
				sn: sn.val()
				
			}
			$.ajax({
				url: "./showSnInfo",
				type: "POST",
				data: JSON.stringify(data), // 转JSON字符串
				dataType: 'json',
				contentType: 'application/json', // contentType很重要
				success: function(result) {
					if(result.status == 200) {
						var str = '<p><b>SN:</b>&nbsp;'+result.sn+'</p>'
						          +'<p><b>上位机:</b>&nbsp;'+result.up_computer+'</p>'
						          +'<p><b>上身板:</b>&nbsp;'+result.up_plate+'</p>'
						          +'<p><b>下身板:</b>&nbsp;'+result.down_plate+'</p>'
						          +'<p><b>雷达:</b>&nbsp;'+result.radar+'</p>'
						          +'<p><b>DLP:</b>&nbsp;'+result.dlp+'</p>'
						          +'<p><b>语音板:</b>&nbsp;'+result.aiui+'</p>'
						          +'<p><b>电机左:</b>&nbsp;'+result.walk_driven_left+'</p>'
						          +'<p><b>电机右:</b>&nbsp;'+result.walk_driven_right+'</p>'
						          +'<p><b>导航板:</b>&nbsp;'+result.navigation+'</p>';
						$(".menu_left .menu_items .sn_list").empty();
						$(".menu_left .menu_items .sn_list").append(str);
						
					}else{
						meg_append(result.message,"red");
					}
				}
			});
		}
	});

	//获得焦点事件
	function getFocus(item) {
		item.focus();
	}

	$(".inHouse_menu .save #sub").click(function() {
		
		if(sn.val() == null) {
			meg_append("sn不能为空！","red");
			getFocus(sn);
		} else {
			var data = {
				sn:sn.val()
			}

			$.ajax({
				url: "./outHouse",
				type: "POST",
				data: JSON.stringify(data), // 转JSON字符串
				dataType: 'json',
				contentType: 'application/json', // contentType很重要
				success: function(result) {
					if(result.status == 200) {
						var back_info = "SN:"+sn.val()+" 出库成功！";
						meg_append(back_info,"#00FFCC");
					}else{
						meg_append(result.message,"red");
					}
				}
			});
		}

	});
	$(".inHouse_menu .save #clear_all").click(function() {
		sn.val("");
		$(".menu_left .menu_items .sn_list").empty();
		$(".inHouse_menu .meg").empty();
	});

	function meg_append(meg, cor) {
		var str = '<strong>提示：</strong><label style="color: ' + cor + ';">' + meg + '</label>';
		$(".inHouse_menu .meg").empty();
		$(".inHouse_menu .meg").append(str);
	}
});